<template>
    <div class="goods-list">
       <!-- <router-link class="goods-item" v-for="item in goods" :key="item.id" tag="div" :to="'/home/goodinfo/'+item.id">
           <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/53641901fbc28cbcdb495b17fdf69e46.jpg?thumb=1&w=200&h=200&f=webp&q=90" alt="">
           <h1 class="title">小米(Mi)小米Note 16G双网通版小米(Mi)</h1>
           <div class="info">
               <p class="price">
                   <span class="now">￥2199</span>
                   <span class="old">￥2399</span>
               </p>
               <p class="sell">
                   <span>{{item.title}}</span>
                   <span>剩余60件</span>
               </p>
           </div>
       </router-link> -->

       <div class="goods-item" v-for="item in goods" :key="item.id" @click="getDetail(item.id)">
           <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/53641901fbc28cbcdb495b17fdf69e46.jpg?thumb=1&w=200&h=200&f=webp&q=90" alt="">
           <h1 class="title">小米(Mi)小米Note 16G双网通版小米(Mi)</h1>
           <div class="info">
               <p class="price">
                   <span class="now">￥2199</span>
                   <span class="old">￥2399</span>
               </p>
               <p class="sell">
                   <span>{{item.title}}</span>
                   <span>剩余60件</span>
               </p>
           </div>
       </div>
       <mt-button type="danger" size="large" @click="getmore">加载更多</mt-button>
    </div>
</template>
<style lang="scss" scoped>
    .goods-list{
        display: flex;
        flex-wrap: wrap; 
        padding: 7px;
        justify-content: space-between;
        padding-bottom: 0;
        .goods-item{
            width: 49%;
            margin-bottom: 10px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            border:1px solid #ccc;
            padding: 2px;
            box-shadow: 0 0 8px #ccc;
            img{
                width: 100%;
            }
            .title{
                font-size: 14px;
            }
        }
        .info{
            p{
                margin: 0;
                padding:5px;
            }
            background-color: #eee;
            .price{
                .now{
                    color:red;
                    font-weight: bold;
                    font-size: 16px;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size:12px;
            }
        }
    }
</style>
<script>
export default {
    data(){
        return {
            goods:[],
            pageindex:1,
            size:6
        }
    },
    created(){
        this.getAllGoods();
    },
    methods:{
        getAllGoods(){
            this.$http.get("getGoods?page="+this.pageindex+"&size="+this.size).then(res=>{
                this.goods=this.goods.concat(res.body.data.records);
            })
        }
        ,
        getmore(){
            this.pageindex+=1;
            this.getAllGoods();;
        },
        getDetail(id){
            this.$router.push("/home/goodinfo/"+id);
        }
    }
}
</script>